package edu.ubb.remeye.exception.handler;

import java.io.IOException;

import org.codecompany.jeha.core.Handler;
import org.codecompany.jeha.populator.Populator;

import edu.ubb.remeye.control.Control;
import edu.ubb.remeye.exception.AbstractException;

/**
 * Exception handler class.
 * 
 * @author Andrew Ianicicau
 *
 */
public class RemEyeExceptionHandler implements Handler {

	///////////////////////////////////////////////////////////////////////////////////
	////		METHODS - RemEyeExceptionHandler
	///////////////////////////////////////////////////////////////////////////////////

	@Override
	public Populator getPopulator() {
		return null;
	}

	/**
	 * Catches all exceptions that have no specially defined handler method.
	 */
	@Override
	public Throwable handle(Throwable throwable, Object... args) {
		return new Throwable();
	}
	
	/**
	 * Catches all exceptions that are extending AbstractException.
	 * @param exception Exception object.
	 * @param args Arguments.
	 * @return
	 */
	public Throwable handle(AbstractException exception, Object... args) {
		Control.showError(exception.getMessage());
		return exception;
	}
	
	/**
	 * Catches all exceptions that are of type IOException.
	 * @param exception Exception object.
	 * @param args Arguments.
	 * @return
	 */
	public Throwable handle(IOException exception, Object... args) {
		String errorMessage = (String) args[0];
		Control.showError(errorMessage);
		return exception;
	}

}
